﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package {
    import com.type.FunctionType;
    import com.utils.File;
    
    import fl.transitions.*;
    import fl.transitions.easing.*;
    
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    import flash.utils.*;

    public class FunctionBar extends MovieClip {

        public var _Body:SimpleButton;//instance name
        public var _Achievement:SimpleButton;//instance name
        public var _Faction:SimpleButton;//instance name
        public var _Black:MovieClip;//instance name
        public var _PackMessage:MovieClip;//instance name
        public var _FriendMessage:MovieClip;//instance name
        public var _Upgrade:SimpleButton;//instance name
        public var _Experience:TextField;//instance name
        public var _ExpLeft:MovieClip;//instance name
        public var _ExperienceBtn:SimpleButton;//instance name
        public var _ExpMiddle:MovieClip;//instance name
        public var _Friend:SimpleButton;//instance name
        public var _Practice:SimpleButton;//instance name
        public var _Research:SimpleButton;//instance name
        public var _SealSoul:SimpleButton;//instance name
        public var _Deploy:SimpleButton;//instance name
        public var _ExpRight:MovieClip;//instance name
        public var _Pack:SimpleButton;//instance name
        public var _StudyStunt:SimpleButton;//instance name
        public var _Fate:SimpleButton;//instance name
        private var _toolbar:Toolbar;
        private var _positionList:Object;
        private var _btnShow:Array;
        private var _onEnd:Function;
        private var _mcTime:Timer;
        private var _btnAdd:Array;
        private var _btnShowArray:Array;
        private var _mcArray:Array;
        private var _tween1:Tween;
        private var _tween2:Tween;
        private var _timer:Timer;
        private var _strX:int;
        private var _strY:int;
        private var _functionBtn:SimpleButton;
        private var _tween3:Tween;
        private var _tween4:Tween;
        private var _light:MovieClip;
        private var _video:MovieClip;

        public function FunctionBar():void{
            this._btnShow = [];
            this._onEnd = new Function();
            this._mcTime = new Timer(20);
            this._btnAdd = [];
            this._mcArray = [];
            this._timer = new Timer(10);
            super();
            addEventListener(Event.ADDED_TO_STAGE, this.addedToStage);
            this._mcTime.addEventListener(TimerEvent.TIMER, this.mcTimeHandler);
        }
        public function set onEnd(_arg1:Function):void{
            this._onEnd = _arg1;
        }
        private function addedToStage(_arg1:Event):void{
            this._toolbar = (parent as Toolbar);
            removeEventListener(Event.ADDED_TO_STAGE, this.addedToStage);
            this.removePackFull();
        }
        public function getPointByType(_arg1:String):Point{
            var _local4:Object;
            var _local2:int = this._btnShowArray.length;
            var _local3:int;
            while (_local3 < _local2) {
                _local4 = this._btnShowArray[_local3];
                if (_arg1 == _local4.name){
                    return (localToGlobal(_local4.point));
                };
                _local3++;
            };
            return (new Point(0, 0));
        }
        public function show(_arg1:Array, _arg2:Array):void{
            this._btnShow = _arg1;
            this._btnAdd = _arg2;
            this.renderLive();
            this.checkBtnCoordinates();
        }
        private function renderLive():void{
            if (this._positionList == null){
                return;
            };
            var _local1:Array = FunctionType.FullList;
            var _local2:int = _local1.length;
            var _local3:int;
            while (_local3 < _local2) {
                this[("_" + _local1[_local3])].x = this._positionList[((_local2 - 1) - _local3)];
                this[("_" + _local1[_local3])].visible = true;
                _local3++;
            };
        }
        private function checkBtnCoordinates():void{
            this._positionList = {};
            var _local1:Array = FunctionType.FullList;
            var _local2:int = _local1.length;
            var _local3:int;
            while (_local3 < _local2) {
                this._positionList[((_local2 - 1) - _local3)] = this[("_" + _local1[_local3])].x;
                this[("_" + _local1[_local3])].visible = false;
                _local3++;
            };
            this._btnShowArray = [];
            var _local4:int = this._btnShow.length;
            var _local5:int;
            while (_local5 < _local4) {
                this.render(this._btnShow, _local4, _local5);
                this._btnShowArray[_local5].mc.x = this._btnShowArray[_local5].x;
                _local5++;
            };
            if (this._btnShow.length >= this._btnAdd.length){
                this.blackLeng(false);
                return;
            };
            this.blackLeng(true);
            this.onAddMc();
            this.loadEffect();
        }
        private function renderBtn():void{
            var _local1:int = this._btnShow.length;
            this._btnShowArray = [];
            var _local2:int;
            while (_local2 < _local1) {
                this.render(this._btnShow, _local1, _local2);
                this._tween1 = new Tween(this._btnShowArray[_local2].mc, "x", Strong.easeIn, this._btnShowArray[_local2].x, this._strX, (_local1 * 0.7), false);
                _local2++;
            };
            this._tween1.addEventListener(TweenEvent.MOTION_FINISH, this.onMc1Finish);
        }
        private function renderMc2():void{
            var _local1:int = this._btnAdd.length;
            this._btnShowArray = [];
            var _local2:int;
            while (_local2 < _local1) {
                this.render(this._btnAdd, _local1, _local2);
                this._tween2 = new Tween(this._btnShowArray[_local2].mc, "x", Back.easeOut, this._strX, this._positionList[((_local1 - 1) - _local2)], (_local1 * 2), false);
                _local2++;
            };
            this._tween2.addEventListener(TweenEvent.MOTION_FINISH, this.onMc2Finish);
            this._timer.addEventListener(TimerEvent.TIMER, this.onTimerEvent);
            this._timer.start();
        }
        private function onTimerEvent(_arg1:TimerEvent):void{
            if (this._functionBtn.alpha < 1){
                this._functionBtn.alpha = (this._functionBtn.alpha + 0.01);
            } else {
                this._timer.stop();
                this._timer.removeEventListener(TimerEvent.TIMER, this.onTimerEvent);
            };
        }
        private function onAddMc():void{
            var _local1:int = this._btnShow.length;
            var _local2:int;
            while (_local2 < _local1) {
                if (this._btnShow[_local2] != this._btnAdd[_local2]){
                    this._strX = this._positionList[(_local1 - _local2)];
                    this._strY = this[("_" + this._btnShow[_local2])].y;
                    this._functionBtn = this[("_" + this._btnAdd[_local2])];
                    this._functionBtn.alpha = 0;
                    return;
                };
                _local2++;
            };
            this._strX = this._positionList[0];
            this._strY = this[("_" + this._btnAdd[_local1])].y;
            this._functionBtn = this[("_" + this._btnAdd[_local1])];
            this._functionBtn.alpha = 0;
        }
        private function loadEffect():void{
            var file:* = null;
            if (this._light){
                this.playLight();
                return;
            };
            file = new File();
            file.onComplete = function ():void{
                _light = (file.getClassObject("Light") as MovieClip);
                _light.gotoAndStop(1);
                _video = (file.getClassObject("MyVideo") as MovieClip);
                _video.gotoAndStop(1);
                _video.blendMode = BlendMode.SCREEN;
                _video.mouseEnabled = false;
                _video.mouseChildren = false;
                playLight();
            };
            file.load((this._toolbar.addonsUrl + "function_bar_effect.swf"));
        }
        private function playLight():void{
            addChild(this._light);
            this._light.x = 0;
            this._light.y = -233;
            this._tween3 = new Tween(this._light, "x", Strong.easeIn, 0, this._strX, 20, false);
            this._tween4 = new Tween(this._light, "y", Strong.easeIn, -233, this._strY, 20, false);
            this._tween3.addEventListener(TweenEvent.MOTION_FINISH, this.onMc3Finsh);
            this._light.gotoAndPlay(2);
        }
        private function playVideo():void{
            addChild(this._video);
            this._video.x = this._strX;
            this._video.y = this._strY;
            this._video.addEventListener("finish", this.mcEnd);
            this._video.gotoAndPlay(2);
        }
        private function onMc1Finish(_arg1:TweenEvent):void{
            this._tween1.removeEventListener(TweenEvent.MOTION_FINISH, this.onMc1Finish);
            this.renderMc2();
        }
        private function onMc2Finish(_arg1:TweenEvent):void{
            this._tween2.removeEventListener(TweenEvent.MOTION_FINISH, this.onMc2Finish);
            this._onEnd();
        }
        private function onMc3Finsh(_arg1:TweenEvent):void{
            this._tween3.removeEventListener(TweenEvent.MOTION_FINISH, this.onMc3Finsh);
            removeChild(this._light);
            this.playVideo();
            this.renderBtn();
        }
        private function mcEnd(_arg1:Event):void{
            this._video.removeEventListener("finish", this.mcEnd);
            this.removeChild(this._video);
        }
        private function render(_arg1:Array, _arg2:int, _arg3:int):void{
            this[("_" + _arg1[_arg3])].visible = true;
            var _local4:Object = {};
            _local4.mc = this[("_" + _arg1[_arg3])];
            _local4.x = this._positionList[((_arg2 - 1) - _arg3)];
            _local4.name = _arg1[_arg3];
            _local4.point = new Point(_local4.x, 47);
            this._btnShowArray[_arg3] = {};
            this._btnShowArray[_arg3] = _local4;
        }
        private function mcTimeHandler(_arg1:TimerEvent):void{
            var _local2:int = this._btnAdd.length;
            var _local3:int = int((627 * (_local2 / 12)));
            if (this._Black.width < _local3){
                this._Black.width++;
                this._Black._Head.x = -(this._Black.width);
            } else {
                this._Black._Mid.width = _local3;
                this._Black._Head.x = -(_local3);
                this._mcTime.stop();
            };
        }
        private function blackLeng(_arg1:Boolean):void{
            var _local2:int = this._btnAdd.length;
            var _local3:int = (_local2 * 10);
            var _local4:int = int((627 * (_local2 / 12)));
            this._Black._Mid.width = _local4;
            this._Black._Head.x = -(_local4);
        }
        public function addPackFull():void{
            this.addChild(this._PackMessage);
            this._PackMessage.x = (this._Pack.x - 10);
        }
        public function removePackFull():void{
            if (this._PackMessage.parent != null){
                this._PackMessage.parent.removeChild(this._PackMessage);
            };
        }
        public function updatePackMessageXY():void{
            this._PackMessage.x = (this._Pack.x - 10);
        }

    }
}//package 
